<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="/misc/css/reset.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/btnicon.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/account.css"  />
<script type="text/javascript" src="/misc/vendors/jquery/jquery_1.2.6.js"></script>
<script type="text/javascript" src="/misc/vendors/o2js/o2js.js"></script>
<script type="text/javascript" src="/misc/vendors/o2js/o2js_build.js"></script>
<script type="text/javascript" >
var baseUrl = "<?=$themeUrl?>";
$().ready(function(){

});
var grids;
</script>
</head>
<style type="text/css">

/* 配送蔬菜选择表格样式 */
table.vegetable{
border-collapse:collapse;
width:100%;
}
table.vegetable th{
background-color:#eee;
color:#666666;
padding:5px;
border:1px solid #CCCCCC;
text-align:center;
}
table.vegetable td{
background-color:#fcfcfc;
color:#999999;
padding:5px;
border:1px solid #CCCCCC;
text-align:center;
} 
table.vegetable tr.on td{
background-color:#EBFAEE;
color:#333333;
}
input.vegetext{
width:50px;
text-align:center;
}
/* 套餐名称 */
.goods_title{
font-size:14px;
font-weight:bold;
margin:10px;
}
/* 选菜表格外框 */
.sltvegetb_div{
height:250px;
overflow-y:auto;
}

/* 选菜份数增加减少按钮 */
.numclick{
background-color:#C3CDDC;
color:#606E7B;
border:1px solid #929CA7;
cursor:pointer;
} 
</style>
<body   style="background-color:#fcfcfc"> 
<script type="text/javascript">
var url_save = '/account_buy/sltbuy'; 
var funcname = "<?=$funcname?>";  //回调函数

var rs_combo = {json_encode($rs_combo)};
var rs_veges = {json_encode($rs_veges)};
var nownum = 0;

/* 保存 */
function fnSave(){
	var nowsltnum = 0;
	var rsslt = [];
	var totalprice = 0;
	
	$('#slt_tbody .vege_tr').each(function(){
		var myid = $(this).attr('myid');
		var vege_num =  parseInt(strToNum($('#nums_'+myid).val()),10);
		if(vege_num <= 0){
			vege_num = 0;
		}
		$('#nums_'+myid).val(vege_num);
		nowsltnum += vege_num;
		if(vege_num > 0){
			rsslt.push({
				vege_id:myid,
				vege_num:vege_num
			});
			totalprice += parseFloat($(this).attr('price')) * vege_num;
		}
	});
	
	if(nowsltnum - rs_combo.min_num >=0 || totalprice>=rs_combo.min_price ){
	
	}else{
		ymPrompt.alert({
			message:'最少选菜 <span class="red">'+rs_combo.min_num+'</span> 份 <label class="gray">或</label><br> 最少选菜总价 <span class="red">'+fnDec(rs_combo.min_price,2)+'</span> 元'
		});
		return false;
	}
	
	if(nowsltnum <= 0){
		ymPrompt.alert({
			message:'您的选菜为 0 份'
		});
		return false;
	}

	var ret_data = {
		combo_id:rs_combo.id,
		combo_name:rs_combo.name,
		combo_sendbdate:rs_combo.sendbdate,
		combo_sendedate:rs_combo.sendedate,
		veges:(rsslt)
	};
	if(funcname != ''){
		eval('parent.'+funcname+'(ret_data);');
	}
	if(typeof parent.ymPrompt == 'object'){
		parent.ymPrompt.close();
	}else{
		window.close();
	}
}
/* 返回 */
function fnReturn(){
	if(defined(parent) && defined(parent.ymPrompt)){
		parent.ymPrompt.close();
	}else{
		window.close();
	}
}
function fnShao(id){
	var vege_num =  parseInt(strToNum($('#nums_'+id).val()),10);
	vege_num = vege_num - 1;
	if(vege_num <= 0){
		vege_num = 0;
	}
	$('#nums_'+id).val(vege_num);
}
function fnAdd(id){
	var vege_num =  parseInt(strToNum($('#nums_'+id).val()),10);
	vege_num = vege_num + 1;
	if(vege_num <= 0){
		vege_num = 0;
	}
	$('#nums_'+id).val(vege_num);
}
</script>  
<div class="goods_title">
	{$rs_combo.name}		
	<span style="font-size:12px;font-weight:normal">（最少选菜 <label class="red">{$rs_combo.min_num}</label> 份 <label class="gray">或</label> 最少选菜总价 <label class="red">{$rs_combo.min_price}</label> 元）</span>
</div>
<div style="margin:10px;">
	<div class="blockdiv">
		<div class="titlediv">选菜</div> 
		<div class="sltvegetb_div">
			<table class="vegetable">
				<thead>
					<tr>
						<th style="width:200px">菜品</th>
						<th style="width:200px">单价</th>
						<th style="width:200px">份数</th>
						<th style="width:200px">小计</th>
					</tr>
				</thead>	
				<tbody id="slt_tbody">
					<?PHP
					if(count($rs_combo['combo_item'])>0){
						foreach($rs_combo['combo_item'] as $v){
								 echo '
						<tr myid="'.$v['vege_id'].'" price="'.$v['price'].'" class="vege_tr" id="vege_tr_'.$v['vege_id'].'">
							<td style="text-align:left">'.$v['vege_name'].'</td>
							<td style="text-align:right">￥'.$v['price'].'</td>
							<td >
								<button class="numclick" onclick="fnShao('.$v['vege_id'].')">-</button>
								<input type="text"  value="0" id="nums_'.$v['vege_id'].'" readonly="readonly" class="vegetext vegenum">
								<button class="numclick" onclick="fnAdd('.$v['vege_id'].')" >+</button>
							</td>
							<td style="text-align:right">￥<span id="price_total_'.$v['vege_id'].'">0.00</td>
						</tr>											 
								 ';
						}
					}
					?>
				</tbody>
			</table>	 
		</div>	
	</div>
</div>
<script type="text/javascript">
$().ready(function(){  
	o2js.build('ymprompt');
	showLoading();   
	setInterval(function(){
		var nowsltnum = 0;//总份数
		var nowpricetotal=0;
		//算每一行的价格
		$('#slt_tbody .vege_tr').each(function(){
			var myid = $(this).attr('myid');
			var price = parseFloat($(this).attr('price'));
			var vege_num =  parseInt(strToNum($('#nums_'+myid).val()),10);
			if(vege_num <= 0){
				vege_num = 0;
			}
			if(vege_num > 0){
				$('#vege_tr_'+myid).addClass('on');
			}else{
				$('#vege_tr_'+myid).removeClass('on');
			}
			$('#price_total_'+myid).html(fnDec(vege_num * price,2));
			nowsltnum += vege_num;
			nowpricetotal += vege_num * price;
		});
		$('#sltnum').html(nowsltnum+'');
		$('#pricetotal').html(fnDec(nowpricetotal,2));
		
		nowpricetotal = parseFloat(nowpricetotal);
		rs_combo.min_price = parseFloat(rs_combo.min_price);
		
		if((nowsltnum - rs_combo.min_num)>=0 || nowpricetotal>=rs_combo.min_price){
			 //可以下一步了
			 $('#btn_save').removeClass('btn_gray').addClass('btn_red');
		}else{
			//不可以下一步
			$('#btn_save').addClass('btn_gray').removeClass('btn_red');
		}
	},500);
});
</script>
<div style="margin:10px;position:relative">
	<button class="btn_gray" id="btn_save" style="float:right;" onclick="fnSave()">确定选择</button>
	<div style="float:right;margin-right:40px;">
	  您共选菜 <span id="sltnum" class="green" style="font-size:16px">0</span> 份 ， 
		产品价格：<span class="red">￥</span><span id="pricetotal" class="red" style="font-size:16px;">0.00</span>
	</div>
</div> 
</body>
</html>